import ij.ImagePlus;
import ij.process.ImageProcessor;

public class draw{
	
	public void draw_edges_with_std(ImagePlus imp)
	{
		ImageProcessor ip = imp.getProcessor();
		double avg_edge_scores =0;
		
		for(int p =0; p< band.numVerts; p++)
		{
			System.out.println("Edge Number:"+ band.ed[p].edge_number+" Edge(x1,y1): ("+ band.ed[p].x1+","+band.ed[p].y1 + " (x2,y2):"+ band.ed[p].x2+","+band.ed[p].y2+" edge score:"+band.ed[p].edge_score);	
		}
		

		double edgSq = 0.0;
		double stdEdgeDev = 0.0;


		for(int i =0; i< band.numVerts ;i++)
		{
			avg_edge_scores += band.ed[i].edge_score;	
		}

		avg_edge_scores = avg_edge_scores/band.numVerts;



		for (int i =0; i< band.numVerts ;i++) {
			double dev = band.ed[i].edge_score - avg_edge_scores;
			edgSq += dev * dev;
		}
		stdEdgeDev = Math.sqrt(edgSq / (band.numVerts ));

		System.out.println(2*stdEdgeDev + avg_edge_scores);
		
		
		//
		for (int i = 0; i < band.numVerts; i++) {
         ip.drawLine(center_mass.xMass, center_mass.yMass, (int) band.ve[i].x, (int) band.ve[i].y);
	}

		///  Draw edges ***************************************************************

		for (int i=0; i<band.numVerts; i++) {	

			//    ip_rgb_v1.setLineWidth();
			if(band.ed[i].edge_score> (avg_edge_scores + 2*stdEdgeDev))
			{
				//ip.setColor(333333333);
				//ip.setColor(555555555);
				ip.setColor(255 & 0xff);
				ip.setLineWidth(10);
				ip.drawLine((int)band.ed[i].x1, (int)band.ed[i].y1, (int)band.ed[i].x2, (int)band.ed[i].y2);
			}
			else if (band.ed[i].edge_score > (stdEdgeDev + avg_edge_scores)){
				//ip.setColor(444444444);
				//ip.setColor(555555555);
				ip.setColor(200 & 0xff);
				ip.setLineWidth(8);
				ip.drawLine((int)band.ed[i].x1, (int)band.ed[i].y1, (int)band.ed[i].x2, (int)band.ed[i].y2);
			}
			else if (band.ed[i].edge_score > avg_edge_scores ){
				//ip.setColor(555555555);
				ip.setColor(150 & 0xff);
				ip.setLineWidth(5);
				ip.drawLine((int)band.ed[i].x1, (int)band.ed[i].y1, (int)band.ed[i].x2, (int)band.ed[i].y2);
			}
			else if (band.ed[i].edge_score > (avg_edge_scores - stdEdgeDev))
			{
				//ip.setColor(666666666);
				//ip.setColor(555555555);
				ip.setColor(100 & 0xff);
				ip.setLineWidth(3); 
				ip.drawLine((int)band.ed[i].x1, (int)band.ed[i].y1, (int)band.ed[i].x2, (int)band.ed[i].y2);
			}
			else
			{
				ip.setColor(0);
				ip.setLineWidth(1);
				//ip.drawLine((int)band.ed[i].x1, (int)band.ed[i].y1, (int)band.ed[i].x2, (int)band.ed[i].y2);
			}


		}


		imp.updateAndDraw();

		System.out.println("Avg edge scores"+avg_edge_scores);
		System.out.println("Standard Dev"+stdEdgeDev);
		
		
		
	}
	
	public void draw_edges_with_std_user_defined()
	{
		ImageProcessor ip = Analysis_.imp_rgb_modified.getProcessor();
		double avg_edge_scores =0;
		
		for(int p =0; p<  Analysis_.numVertex_User_Defined; p++)
		{
			System.out.println("Edge Number:"+ band.ed[p].edge_number+" Edge(x1,y1): ("+ band.ed[p].x1+","+band.ed[p].y1 + " (x2,y2):"+ band.ed[p].x2+","+band.ed[p].y2+" edge score:"+band.ed[p].edge_score);	
		}
		

		double edgSq = 0.0;
		double stdEdgeDev = 0.0;


		for(int i =0; i< Analysis_.numVertex_User_Defined ;i++)
		{
			avg_edge_scores += band.ed[i].edge_score;	
		}

		avg_edge_scores = avg_edge_scores/Analysis_.numVertex_User_Defined;



		for (int i =0; i< Analysis_.numVertex_User_Defined ;i++) {
			double dev = band.ed[i].edge_score - avg_edge_scores;
			edgSq += dev * dev;
		}
		stdEdgeDev = Math.sqrt(edgSq / (Analysis_.numVertex_User_Defined ));

		System.out.println(2*stdEdgeDev + avg_edge_scores);
		

		///  Draw edges ***************************************************************

		for (int i=0; i<Analysis_.numVertex_User_Defined; i++) {	

			//    ip_rgb_v1.setLineWidth();
			if(band.ed[i].edge_score> (avg_edge_scores + 2*stdEdgeDev))
			{
				//ip.setColor(333333333);
				ip.setColor(555555555);
				ip.setLineWidth(10);
				ip.drawLine((int)band.ed[i].x1, (int)band.ed[i].y1, (int)band.ed[i].x2, (int)band.ed[i].y2);
			}
			else if (band.ed[i].edge_score > (stdEdgeDev + avg_edge_scores)){
				//ip.setColor(444444444);
				ip.setColor(555555555);
				ip.setLineWidth(8);
				ip.drawLine((int)band.ed[i].x1, (int)band.ed[i].y1, (int)band.ed[i].x2, (int)band.ed[i].y2);
			}
			else if (band.ed[i].edge_score > avg_edge_scores ){
				ip.setColor(555555555);
				ip.setLineWidth(5);
				ip.drawLine((int)band.ed[i].x1, (int)band.ed[i].y1, (int)band.ed[i].x2, (int)band.ed[i].y2);
			}
			else if (band.ed[i].edge_score > (avg_edge_scores - stdEdgeDev))
			{
				//ip.setColor(666666666);
				ip.setColor(555555555);
				ip.setLineWidth(3); 
				ip.drawLine((int)band.ed[i].x1, (int)band.ed[i].y1, (int)band.ed[i].x2, (int)band.ed[i].y2);
			}
			else
			{
				//ip.setColor(0);
				//ip.setLineWidth(1);
				//ip.drawLine((int)band.ed[i].x1, (int)band.ed[i].y1, (int)band.ed[i].x2, (int)band.ed[i].y2);
			}


		}


		 Analysis_.imp_rgb_modified.updateAndDraw();

		System.out.println("Avg edge scores"+avg_edge_scores);
		System.out.println("Standard Dev"+stdEdgeDev);
		
		
		
	}
	
	
	
	
}